package com.btcode.common;

public class ExecuteTimeUtil {

    private long startTime;
    private long lastTime = 0;

    public ExecuteTimeUtil() {
        startTime = System.currentTimeMillis();
        lastTime = startTime;
    }

    /**
     * 获取距离上一次调用该方法的时间间隔
     */
    public long getLastDiff() {
        long endTime = System.currentTimeMillis();
        long diff = endTime - lastTime;
        lastTime = endTime;
        return diff;
    }

    public double getLastDiffInSecond(){
        long diff = getLastDiff();
        double timeCost = (double)diff;
        double costInSecond = timeCost / 1000d;
        return costInSecond;
    }

    /**
     * 获取距离构造该对象到现在的时间间隔
     */
    public long getWholeDiff() {
        long endTime = System.currentTimeMillis();
        lastTime = endTime;
        long diff = endTime - startTime;
        return diff;
    }

}
